#!/usr/bin/python

import urllib2
import sys
import feedparser

url = 'http://www.20minutes.fr/rss/une.xml'
font = '/home/gromain/DPF/EllianarellesPath.ttf'
posx = 25
posy = 120
address = '/home/gromain/DPF/'
base = '20minutes/base.jpg'
target = '20minutes/20minutes.png'

print 'MAJ de 20minutes.fr ...'

feed = feedparser.parse(url)

updatefile = open(address + '20minutes/update.sh' , 'w')
updatefile.write('#!/bin/bash \n\n')
updatefile.write('gm convert ')
updatefile.write('-font ' + font + ' -pointsize 50 -fill black -draw \"text 200,60 \\\"' + feed.channel.title.encode("utf-8") + '\\\" \" ')

for i in range(0,14):
	updatefile.write('-font ' + font + ' -pointsize 30 -draw \"text ' + str(posx) + ',' + str(posy) + ' \\\"' + feed.entries[i].title.encode("utf-8") + '\\\" \" ')
	posy = posy + 45

updatefile.write('-font ' + font + ' -pointsize 25 -draw \"text ' + str(posx) + ',760 \\\"' + feed.entries[0].updated.encode("utf-8") + '\\\" \" ')
updatefile.write(address + base + ' ')
updatefile.write(address + target)
updatefile.close()

print '20minutes.fr, script python terminé...'
